<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>PHP登录</title>
</head>
<body>
	
	<div>
		用户名：<input id="username" type="text" autocomplete="off"><br><br>
		密码：<input id="password" type="password" autocomplete="off"><br><br>
		验证码：<img src="http://127.0.0.1/PHPStudy/login/loginCode.php" width="150" height="35" id="codeImg" border="1">
		<input type="text" name="code" id="code" autocomplete="off">
		<br><br>
		<button id="submit">登录</button>
	</div>
	
	
	<script src="jquery-3.2.1.min.js"></script>
	<script>
		$("#codeImg").click(function(){
			$(this).attr("src", "http://127.0.0.1/PHPStudy/login/loginCode.php?"+Math.random());
		});

		$("#submit").click(function(){
			let username = $("#username").val();
			let password = $("#password").val();
			let code = $("#code").val();
			$.ajax({
				type: "POST",
				url: "http://127.0.0.1/PHPStudy/login/login-modul.php",
				dataType: "json",
				data: {"username":username,"password":password,"code":code},
				success:function(res){
					console.log(res);
					if(res.status == "yes"){
						alert(res.msg);
					}else{
						alert(res.msg);
					}
				},
				error:function(msg){
					console.log("ERROR:",msg);
				}
			})
		});
	</script>
</body>
</html>